; 下载并安装 ScreenCapture 库
; 你可以从 GitHub 上下载 ScreenCapture 库并将其放在你的脚本目录中

#Include ScreenCapture.ahk

; 定义一个热键，例如 F1，来触发屏幕截图
F1::  ; 当按下 F1 键时
{
    ; 截取整个屏幕
    ImageFile := A_ScriptDir "\screenshot.png"
    CaptureScreen(ImageFile)

    ; 显示截图
    Run, %ImageFile%

    return
}

; 截取整个屏幕
CaptureScreen(OutputFile) {
    ; 获取屏幕尺寸
    SysGet, MonitorWorkArea, MonitorWorkArea, 0
    Width := MonitorWorkAreaRight - MonitorWorkAreaLeft
    Height := MonitorWorkAreaBottom - MonitorWorkAreaTop

    ; 创建 GDI+ 对象
    hDC := DllCall("GetDC", "Ptr", 0, "Ptr")
    hMemDC := DllCall("CreateCompatibleDC", "Ptr", hDC, "Ptr")
    hBitmap := DllCall("CreateCompatibleBitmap", "Ptr", hDC, "int", Width, "int", Height, "Ptr")
    DllCall("SelectObject", "Ptr", hMemDC, "Ptr", hBitmap)

    ; 截图
    DllCall("BitBlt", "Ptr", hMemDC, "int", 0, "int", 0, "int", Width, "int", Height, "Ptr", hDC, "int", 0, "int", 0, "UInt", 0x00CC0020)

    ; 保存为图片
    DllCall("gdiplus\GdipCreateBitmapFromHBITMAP", "Ptr", hBitmap, "Ptr", 0, "Ptr*", pBitmap)
    DllCall("gdiplus\GdipSaveImageToFile", "Ptr", pBitmap, "Str", OutputFile, "Str", "image/png", "Ptr", 0)
    DllCall("gdiplus\GdipDisposeImage", "Ptr", pBitmap)

    ; 释放资源
    DllCall("DeleteObject", "Ptr", hBitmap)
    DllCall("DeleteDC", "Ptr", hMemDC)
    DllCall("ReleaseDC", "Ptr", 0, "Ptr", hDC)
}
